package flexUnitTests.testCases
{
	import com.competentum.builders.BindsBuilder;
	import com.competentum.builders.DataBuildersFactory;
	import com.competentum.builders.EmployeesBuilder;
	import com.competentum.builders.PreferencesBuilder;
	import com.competentum.builders.ProjectsBuilder;
	import com.competentum.data.parser.CSVParser;
	import com.competentum.data.parser.XMLParser;
	import com.competentum.engines.BindsEngine;
	import com.competentum.engines.CommandPanelEngine;
	import com.competentum.engines.EmployeesEngine;
	import com.competentum.engines.EngineFactory;
	import com.competentum.engines.InputOutputEngine;
	import com.competentum.engines.ProjectsEngine;
	import com.competentum.engines.ShortCutsEngine;
	import com.competentum.vos.BindVO;
	import com.competentum.vos.EmployeeVO;
	import com.competentum.vos.ProjectVO;
	import com.competentum.windows.Scope;
	import com.competentum.lib.engines.AbstractEngine;
	import com.competentum.lib.engines.AbstractEngineFactory;
	
	import org.flexunit.asserts.assertEquals;

	public class CSVParserTest
	{
		private var SCOPE:Scope = new Scope(null);
		
		private var parser:CSVParser;
		
		private var csv:String = '\t\tProject1\tProject2\tProject3\n\t\t10\t20\t30\nEmployee1\t15\t\t7\t9\nEmployee2\t20\t4\t6\t\nEmployee3\t25\t5\t6\t7';
		
		[Before]
		public function setUp():void
		{
			var dataBuildersFactory:DataBuildersFactory = new DataBuildersFactory();
			parser = new CSVParser();
		}
		
		[Test]
		public function test():void
		{
			parser.parse(csv, SCOPE);
			var bindsBuilder:BindsBuilder = DataBuildersFactory.getDataBuilder(BindsBuilder.TYPE, SCOPE) as BindsBuilder;
			var employeesBuilder:EmployeesBuilder = DataBuildersFactory.getDataBuilder(EmployeesBuilder.TYPE, SCOPE) as EmployeesBuilder;
			assertEquals(employeesBuilder.itemsCount, 3);
			
			var employee:EmployeeVO = employeesBuilder.getItemByIndex(0) as EmployeeVO;
			assertEquals(employee.name, 'Employee1');
			assertEquals(employee.hours, 15);
			assertEquals(employee.team, 'no');
			assertEquals(bindsBuilder.getTotalReservedHours(employee), 16);
			
			employee = employeesBuilder.getItemByIndex(1) as EmployeeVO;
			assertEquals(employee.name, 'Employee2');
			assertEquals(employee.hours, 20);
			assertEquals(employee.team, 'no');
			assertEquals(bindsBuilder.getTotalReservedHours(employee), 10);
			
			employee = employeesBuilder.getItemByIndex(2) as EmployeeVO;
			assertEquals(employee.name, 'Employee3');
			assertEquals(employee.hours, 25);
			assertEquals(employee.team, 'no');
			assertEquals(bindsBuilder.getTotalReservedHours(employee), 18);
			
			var projectsBuilder:ProjectsBuilder = DataBuildersFactory.getDataBuilder(ProjectsBuilder.TYPE, SCOPE) as ProjectsBuilder;
			assertEquals(projectsBuilder.itemsCount, 3);

			var project:ProjectVO = projectsBuilder.getItemByIndex(0) as ProjectVO;
			assertEquals(project.name, 'Project1');
			assertEquals(project.groupingAttribute, 'no');
			assertEquals(project.hours, 10);
			assertEquals(project.comments, null);
			assertEquals(bindsBuilder.getTotalReservedHours(project), 9);

			project = projectsBuilder.getItemByIndex(1) as ProjectVO;
			assertEquals(project.name, 'Project2');
			assertEquals(project.groupingAttribute, 'no');
			assertEquals(project.hours, 20);
			assertEquals(project.comments, null);
			assertEquals(bindsBuilder.getTotalReservedHours(project), 19);

			project = projectsBuilder.getItemByIndex(2) as ProjectVO;
			assertEquals(project.name, 'Project3');
			assertEquals(project.groupingAttribute, 'no');
			assertEquals(project.hours, 30);
			assertEquals(project.comments, null);
			assertEquals(bindsBuilder.getTotalReservedHours(project), 16);

			var outCSV:String = parser.export(SCOPE);
			assertEquals(outCSV, csv);
		}
	}
}